var validatedFieldsStack = new Array();

function showRequiredFieldsByNocType(nocType){
	var reqFields = nocFieldMapping[nocType];
	$(".changableField").css("display","none");
	eraseStack();
	for (indx in reqFields)
	{
		$("."+reqFields[indx]+"Cont").css("display","block");
		$("#"+reqFields[indx]).rules("add", { required: true });
		validatedFieldsStack.push(reqFields[indx]);
	}
}

function eraseStack(){
	var elem = null;
	while((elem = validatedFieldsStack.pop())!=null){
		$("#"+elem).rules("add", { required: false });
		$("#"+elem).val("");
		if(elem == "country" && $.browser.msie && $.browser.version.substr(0,1)<7){
			$("#cuselFrame-country .cuselText").html("");
			$("#cusel-scroll-country span.cuselActive").removeClass("cuselActive");
			$("#cusel-scroll-country span[val='']").addClass("cuselActive");
		}
	}
	
}

function showNocsByLang(lang){
	var oldOne = $("#nocAndLetters").val();
	$("#nocAndLetters").val("");
	if(lang==""){
		$("#nocAndLettersCont").css("display","none");
	} else {
		var nocs = nocLangMapping[lang];
		showAndHideValues(nocs, oldOne);
		$("#nocAndLettersCont").css("display","block");
	}
}


function showAndHideValues(nocs, oldOne){
	if($.browser.msie && $.browser.version.substr(0,1)<7){
		var params = {
				refreshEl : "#nocAndLetters"
			};
		cuSelRefresh(params);
		
		if(!($("#ie6OptionsBuffer").length)){
			$("body").append("<div id='ie6OptionsBuffer' style='display:none;'></div>");
			$("#ie6OptionsBuffer").html($("#cusel-scroll-nocAndLetters").html());
		}
		$("#cusel-scroll-nocAndLetters > span").remove();
		$("#cuselFrame-nocAndLetters .cuselText").html("");
		$('<span val=""></span>').appendTo('#cusel-scroll-nocAndLetters');
		var selected = false;
		for(indx in nocs){
			var node = $("#ie6OptionsBuffer").children("span[val='"+nocs[indx]+"']").clone();
			node.removeClass("cuselActive");
			if(nocs[indx] == oldOne){
				node.addClass("cuselActive");
				$("#nocAndLetters").val(oldOne);
    			$("#cuselFrame-nocAndLetters .cuselText").html(node.html());
    			selected = true;
			}
			node.appendTo('#cusel-scroll-nocAndLetters');
		}
		if(!selected){
			$("#cusel-scroll-nocAndLetters span[val='']").addClass("cuselActive");
		}
		
		cuSelRefresh(params);
	} else {
		$("#nocAndLetters > option").css("display", "none");
		var selected = false;
		for(indx in nocs){
			$("#nocAndLetters option[value='"+nocs[indx]+"']").css("display", "block").removeAttr("selected");
			if(nocs[indx]==oldOne){
				selected = true;
			}
		}
		if(selected){
			$("#nocAndLetters option[value='"+oldOne+"']").attr("selected", "selected");
			$("#nocAndLetters").val(oldOne);
		} else {
			$("#nocAndLetters option[value='']").attr("selected", "selected");
		}
		
	}
}